<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>菜单树</title>
    <link rel="stylesheet" href="/static/css/element-ui/element-ui.css">
    <link rel="stylesheet" href="/static/css/public.css">
    <script src="/static/js/jquery.min.js"></script>
    <script src="/static/js/layer/layer.js"></script>
    <script src="/static/js/vue.min.js"></script>
    <script src="/static/js/element-ui.js"></script>
    <script src="/static/js/public.js"></script>
</head>
<body>
<div v-cloak id="app">
    <div class="ml-15 mt-20">
        <el-tree ref="tree"
                 :data="treeData"
                 show-checkbox
                 node-key="id"
                 disabled="true"
                 default-expand-all
                 :props="defaultProps">
        </el-tree>
    </div>
    <input type="hidden" value="${roleId}" id="roleId">
</div>
<script>
    $(function () {
        data.roleId = $("#roleId").val();
        methods.getMenuTree();
    });

    var data = {
        flag: "",
        roleId: "",
        treeData: [],
        defaultProps: {
            children: 'children',
            label: 'name'
        },
        selectIds: [],
        oldIds: ""
    };

    var methods = {
        getSelectKeys: function () {
            data.selectIds = vm.$refs.tree.getCheckedKeys();
        },
        getMenuTree: function () {
            var load = layer.load(2);
            ajax.post("/system/menu/getMenuTree", {}, function (res) {
                data.treeData = res.data;
                methods.getCheckedMenu(load);
            })
        },
        getCheckedMenu: function (load) {
            ajax.post("/system/menu/getMenuByRole", {
                roleId: data.roleId
            }, function (res) {
                layer.close(load);
                data.oldIds = res.data.join(",");
                vm.$refs.tree.setCheckedKeys(res.data);
            });
        }
    };
    var vm = new Vue({data: data, methods: methods}).$mount("#app");
</script>
</body>
</html>
